
using System;
using System.Linq;
using Csla;
using Csla.Data;

namespace HousingInfo.Library
{ 
	public partial class CategoryBOList : Csla.BusinessListBase<CategoryBOList, CategoryBO>
	{

		#region Authorization Rules

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of CategoryBOList
			//AuthorizationRules.AllowCreate(typeof(CategoryBOList), "CategoryBOListCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(CategoryBOList), "CategoryBOListEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(CategoryBOList), "CategoryBOListDeleteGroup"));
		}
		#endregion //Authorization Rules

        #region Trang Admin - Danh Muc

        #region Ham Lay danh sach tung danh muc
        public static CategoryBOList GetCategoryBOList_ByType(bool isnhadat, bool isdiendan, bool isngonngu, bool istintuc)
        {
            return DataPortal.Fetch<CategoryBOList>(new FilterCriteriaGetCategory_ByType(isnhadat, isdiendan, isngonngu, istintuc));
        }
        #endregion //End ham lay tung loai danh muc

        #region khai bao tham so
        private class FilterCriteriaGetCategory_ByType
        {
            public bool nhadat;
            public bool diendan;
            public bool ngonngu;
            public bool tintuc;
            public FilterCriteriaGetCategory_ByType(bool nd, bool dd, bool nn, bool tt)
            {
                this.nhadat = nd;
                this.diendan = dd;
                this.ngonngu = nn;
                this.tintuc = tt;
            }
        }
        #endregion//end khai bao tham so

        #region Truy cap du lieu
        private void DataPortal_Fetch(FilterCriteriaGetCategory_ByType criteria)
        {
            bool cancel = false;
            OnFetching(ref cancel);
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;
                if (criteria.diendan == true)
                {
                    this.AddRange(
                        from row in mgr.DataContext.Categories
                        where row.IsTopicForum == true
                        select CategoryBO.GetCategoryBO(row.CategoryID)
                    );
                }
                else if (criteria.ngonngu == true)
                {
                    this.AddRange(
                        from row in mgr.DataContext.Categories
                        where row.IsLanguage == true
                        select CategoryBO.GetCategoryBO(row.CategoryID)
                    );
                }
                else if (criteria.nhadat == true)
                {
                    this.AddRange(
                        from row in mgr.DataContext.Categories
                        where row.IsHousingCategory == true
                        select CategoryBO.GetCategoryBO(row.CategoryID)
                    );
                }
                else
                {
                    this.AddRange(
                        from row in mgr.DataContext.Categories
                        where row.IsNewsCategory == true
                        select CategoryBO.GetCategoryBO(row.CategoryID)
                    );
                }

                RaiseListChangedEvents = true;
            }//using


            //OnFetched();
        }
        #endregion//end truy cap

        #endregion //End Trang Admin Danh muc

       
    }
}

